package leetcode;

public class Code45 {
    public static void main(String[] args) {
        System.out.println(new Code45().jump(new int[]{
                2,3,1,1,4
        }));
    }

    public int jump(int[] nums) {
        int nowSpeed = 0;
        int speed = 0;
        while (nowSpeed < nums.length - 1) {
            speed++;
            int maxRt = 0;
            int index = 0;
            for (int a = nowSpeed; a <= nowSpeed + nums[nowSpeed]; a++) {
                if(a>=nums.length-1){
                    return speed;
                }
                if (a + nums[a] > maxRt) {
                    maxRt = a + nums[a];
                    index = a;
                }
            }
            nowSpeed = index;
        }
        return speed;
    }
}
